#include <vector>
#include <iostream>
#include <unordered_set>
#include <unordered_map>

using namespace std;

class Solution 
{
public:
    vector<int> twoSum(vector<int>& nums, int target) 
    {
        unordered_multimap<int, int> um;
        for(int i = 0; i < nums.size(); i++)
        {
            um.emplace(nums[i], i);
        }
        vector<int> result;
        for(auto it = um.begin(); it != um.end(); it++)
        {
            int num1 = it->first;
            int num2 = target - num1;
            auto it2 = um.find(num2);
            if(it2 != it && it2 != um.end())
            {
                result.push_back(it->second);
                result.push_back(it2->second);
                break;
            }
        }
        return result;
    }
};

int main() 
{
    Solution solution;
    
    // 测试案例1: [2,7,11,15], target = 9
    cout << "测试案例1:" << endl;
    vector<int> nums1 = {2, 7, 11, 15};
    int target1 = 9;
    cout << "输入: nums = [2,7,11,15], target = " << target1 << endl;
    vector<int> result1 = solution.twoSum(nums1, target1);
    cout << "输出: [" << result1[0] << "," << result1[1] << "]" << endl;
    cout << "期望: [0,1]" << endl << endl;
    
    // 测试案例2: [3,2,4], target = 6
    cout << "测试案例2:" << endl;
    vector<int> nums2 = {3, 2, 4};
    int target2 = 6;
    cout << "输入: nums = [3,2,4], target = " << target2 << endl;
    vector<int> result2 = solution.twoSum(nums2, target2);
    cout << "输出: [" << result2[0] << "," << result2[1] << "]" << endl;
    cout << "期望: [1,2]" << endl << endl;
    
    // 测试案例3: [3,3], target = 6
    cout << "测试案例3:" << endl;
    vector<int> nums3 = {3, 3};
    int target3 = 6;
    cout << "输入: nums = [3,3], target = " << target3 << endl;
    vector<int> result3 = solution.twoSum(nums3, target3);
    cout << "输出: [" << result3[0] << "," << result3[1] << "]" << endl;
    cout << "期望: [0,1]" << endl << endl;
    
    // 测试案例4: [1,5,3,7,9], target = 12
    cout << "测试案例4:" << endl;
    vector<int> nums4 = {1, 5, 3, 7, 9};
    int target4 = 12;
    cout << "输入: nums = [1,5,3,7,9], target = " << target4 << endl;
    vector<int> result4 = solution.twoSum(nums4, target4);
    cout << "输出: [" << result4[0] << "," << result4[1] << "]" << endl;
    cout << "期望: [2,3] 或 [1,4]" << endl << endl;
    
    // 测试案例5: [-1,-2,-3,-4,-5], target = -8
    cout << "测试案例5 (负数):" << endl;
    vector<int> nums5 = {-1, -2, -3, -4, -5};
    int target5 = -8;
    cout << "输入: nums = [-1,-2,-3,-4,-5], target = " << target5 << endl;
    vector<int> result5 = solution.twoSum(nums5, target5);
    cout << "输出: [" << result5[0] << "," << result5[1] << "]" << endl;
    cout << "期望: [2,4]" << endl << endl;
    
    return 0;
}